Imports System.Net.Mail

Partial Class PasswordReset
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Private Sub BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCancel.Click
        Response.Redirect("default.aspx")

    End Sub

    Private Sub BtnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReset.Click

        'get the UID from SQL by the email address
        Dim strAccountName, strPassword As String
        strAccountName = FunctionsSecurity.GetActiveAccountNamebyEmail(txtEmailAddress.Text)

        If strAccountName = "" Then
            LblMessage.Text = "Your Email Address Was Not Found."
            Exit Sub
        Else
            'Dim x As New GeneratePassword.VBServCom
            'strPassword = x.ReturnPassword(6)

            'FunctionsSecurity.FunctionSetPassword(strAccountName, strPassword)
            'SendPasswordResetEmail(strAccountName, strPassword)
            strPassword = NENAData.NENAMember.Account.Password.Generate(6)
            NENAData.NENAMember.Account.Password.Set(strAccountName, strPassword)

            NENAData.Email.Send.PasswordReset(strAccountName, txtEmailAddress.Text, strPassword)

            Response.Redirect("passwordresetsuccess.aspx")

        End If

    End Sub

    Private Sub SendPasswordResetEmail(ByVal strAccountName As String, ByVal strPassword As String)
        'Dim strbuilder As New StringBuilder

        'strbuilder.Append("<br/>Hello, you have requested a new NENA.ca password; below are your new login credentials:").AppendLine.AppendLine()
        'strbuilder.Append("&nbsp;&nbsp;Username: <b>").Append(strAccountName).Append("</b>").AppendLine()
        'strbuilder.Append("&nbsp;&nbsp;Password: <b>").Append(strPassword).Append("</b>").AppendLine.AppendLine()
        'strbuilder.Append("If you are attempting to renew your account or update your demographics, please visit our Membership website at").AppendLine.Append("http://www.nena.ca/membership ").AppendLine.AppendLine()
        'strbuilder.Append("if you are a current member, you can enter your password and username in the login box on the website").AppendLine.Append("http://www.nena.ca ").AppendLine.AppendLine()
        'strbuilder.Append("If we can be of any assistance to you please feel free to contact us.").AppendLine()
        'strbuilder.Append("You can contact us through the NENA Message Board link on the NENA website if you are a current member.").AppendLine()
        'strbuilder.Append("If you are unable to log in to your NENA account, please reply to this email.").AppendLine.AppendLine()
        'strbuilder.Append("Sincerely,").AppendLine.Append("NENA Site Administrators")

        'Dim message As New MailMessage

        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtsperver") = "mailout.accesscomm.ca"
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "gary.pronych"
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "garyrhd"

        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtsperver") = "localhost"
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "pronychgary"
        ''objMail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "garyrqhr"

        'message.From = New MailAddress("WebSiteAdministrator@nena.ca", "NENA WebSite Administrator")
        'message.To.Add(New MailAddress(txtEmailAddress.Text))
        'message.Subject = "NENA Password Reset"
        'message.IsBodyHtml = True
        'message.Body = strbuilder.ToString

        ''SmtpMail.SmtpServer = "mailout.accesscomm.ca"
        'Dim client As New SmtpClient("localhost")
        'client.Send(message)

    End Sub
End Class
